// 获取地址栏参数
interface urlType {
    id: string,
    a?: string,
    title?:string
}

interface ItemType {
    img: string,
    id: string,
    title: string

}

interface DataType {
    code: number,
    data1: ItemType
}

// 解析地址栏参数
function UrlObj (url: string) {
    const urlArr = url.split('?')[1].split('&')

    let obj:urlType | {} = {}

    urlArr.forEach(item => {
        const keys = item.split("=")[0]

        obj = {
            ...obj,
            [keys]: item.split("=")[1]
        }
    })

    return obj as urlType


}

const urlValue:urlType = UrlObj(location.href);

Ajax(`/api/getDetail?id=${urlValue.id}`, (data:DataType) => {
    render(data.data1)
})

function render(data:ItemType) {
    const detailBox = document.querySelector('.detailBox');

    (detailBox as Element).innerHTML = `
        <div>
            <h1>${data.title}</h1>
            <img  src="${data.img}" alt/>
        </div>
    `
}
